-
Notifications
You must be signed in to change notification settings - Fork 1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Use async processing to avoid database timeouts #437
Conversation
@@ -55,7 +59,9 @@ public MessageStateEventListener(ObjectMapper objectMapper, | |||
* | |||
* @param event the event to respond to | |||
*/ | |||
@EventListener(value = NotificationStateEventDto.class) | |||
@Transactional(propagation = Propagation.REQUIRES_NEW) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we have had transaction lock issues with postgres (aws rds) when using Propagation.REQUIRES_NEW
previously, @mpgxvii can you elaborate the issues we faced previously.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Indeed, using TransactionalEventListener + Async was essential, because it only opens a new transaction once the old one is committed. In earlier tests with other permutations, the transactions would overlap and block the HikariCP thread pool.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah ok I see, sounds good. Yes we had to remove the REQUIRES_NEW
propagation previously because it was resulting in "Too many connections" issue which was blocking other transactions and causing inconsistent states.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@mpgxvii perhaps we can test this with our stage cluster?
In the previous handling of events, event were handled immediately during the transaction, in the same thread. This caused a lot of delays, blocking the database threads. The EventListener annotations are replaced by TransactionalEventListener to ensure that the previous transaction has been committed before processing the event. It explicitly creates a new transaction to avoid overlapping transactions. Finally, it enables async processing to avoid the existing transaction threads being blocked.
a030664
to
c73d2d9
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, thanks!
In the previous handling of events, event were handled immediately during the transaction, in the same thread. This caused a lot of delays, blocking the database threads. The
EventListener
annotations are replaced byTransactionalEventListener
annotations to ensure that the previous transaction has been committed before processing the event. It explicitly creates a new transaction to avoid overlapping transactions. Finally, theAsync
annotation enables async processing to avoid the existing transaction threads being blocked.This fixes an issue that caused timeouts if the fcm handling had timeouts.